package me.xue.communityhealth.repo;

import com.github.pagehelper.Page;
import me.xue.communityhealth.model.Drug;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface DrugRepository {

    @Insert("INSERT INTO `drug`(num,name,abbreviate,cost,drugUnit,drugDepot,drugPlace,drugSupplier,drugType,description,produceDate,storageTime,who,photo) " +
            "VALUES(#{num},#{name},#{abbreviate},#{cost},#{drugUnit},#{drugDepot},#{drugPlace},#{drugSupplier},#{drugType},#{description},#{produceDate},#{storageTime},#{who},#{photo})")
    int save(Drug drug);

    @Update("UPDATE `drug` " +
            "SET num=#{num},name=#{name},abbreviate=#{abbreviate},cost=#{cost},drugUnit=#{drugUnit},drugDepot=#{drugDepot},drugPlace=#{drugPlace},drugSupplier=#{drugSupplier},drugType=#{drugType},description=#{description},produceDate=#{produceDate},storageTime=#{storageTime},who=#{who},photo=#{photo} " +
            "WHERE id=#{id}")
    int update(Drug drug);

    @Delete("DELETE FROM `drug` WHERE `id`=#{id}")
    int delete(int id);

    @Select("SELECT * FROM `drug` WHERE `id`=#{id}")
    Drug findOne(Integer id);

    @Select("SELECT * FROM `drug` WHERE `abbreviate` LIKE #{abbreviate}")
    List<Drug> findByAbbreviate(String abbreviate);

    @Select("SELECT * FROM `drug`")
    Page<Drug> pagedDrugs();
}
